/************************************
 * Package: RGcpp					*
 * Authors: Rui Eduardo Gouveia Gil	*
 * Date: 2010						*
 ************************************/
#include "rgcpp/exceptions/ExceptionHandler.h"
#include "rgcpp/exceptions/Exception.h"
#include "rgcpp/utils/LogHandler.h"

namespace rgcpp
{

Exception::Exception(const std::string& message)
{
	this->name = "Exception";
	this->message = message;
	this->stackTrace = ExceptionHandler::getStackTraceString();
}

Exception::~Exception() throw ()
{

}

void Exception::printStackTrace()
{
	const std::string& stackTrace = this->getStackTrace();
	LOG_ERROR_STR(stackTrace);
}

std::string Exception::getStackTrace()
{
	std::string result;
	std::stringstream stream;

	stream << this->stackTrace;
	stream << this->information << std::endl;
	stream << this->name << ": " << this->message;

	result = stream.str();
	return result;
}

void Exception::setExceptionInformation(const char* file, const  char* function, const int line)
{
	std::stringstream stream;

	stream << file << ": line " << line << " on " << function;

	this->information = stream.str();
}

Exception::Exception(const std::string& name, const std::string& message)
{
	this->name = name;
	this->message = message;
	this->stackTrace = ExceptionHandler::getStackTraceString();
}

}
